<?php

namespace App\Http\Controllers\Home;

use App\Models\Member;

class MemberController extends BaseController
{
    public function __construct(Member $member)
    {
        parent::__construct();
        $this->member = $member;
    }

    public function getIndex()
    {
        $memberInfo = $this->memberInfo;
        debug(session('memberInfo'));
        return view('home.index',compact('memberInfo'));
    }

    public function getLogin()
    {
        if ($this->memberInfo) {
            return redirect(action('Home\MemberController@getIndex'));
        }
        return view('home.login');
    }

    public function postLogin()
    {
        $res = $this->member->login(request());
        if (!$res) {
            return redirect(action('Home\MemberController@getLogin'));
        }
        return redirect(action('Home\MemberController@getIndex'));
    }
    
    public function getLogout()
    {
        $this->member->logout();
        return redirect(action('Home\MemberController@getLogin'));
    }

}
